package com.novasoftware.novagooglemap.db.builder;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.ContentValues;
import android.database.Cursor;

import com.novasoftware.novagooglemap.db.DataBaseBuilder;
import com.novasoftware.novagooglemap.db.entity.Natatoria;

public class NatatoriaBuilder implements DataBaseBuilder<Natatoria> {

	private String root;
	
	public String getRoot() {
		return this.root;
	}

	public void setRoot(String root) {
		this.root = root;
	}

	public String table() {
		return "Natatoria";
	}

	@Override
	public Natatoria build(Cursor query) {
		int Id = query.getColumnIndex("Id");
		int Name = query.getColumnIndex("Name");
		int GeoPoint = query.getColumnIndex("GeoPoint");
		int CreateDate = query.getColumnIndex("CreateDate");
		
		Natatoria natatoria = new Natatoria();
		natatoria.Id = query.getInt(Id);
		natatoria.Name = query.getString(Name);
		natatoria.GeoPoint = query.getString(GeoPoint);
		natatoria.CreateDate = query.getString(CreateDate);
		
		return natatoria;
	}

	@Override
	public ContentValues deconstruct(Natatoria entity) {
		ContentValues values = new ContentValues();
		if(entity.Id>0) values.put("Id", entity.Id);
		values.put("Name", entity.Name);
		values.put("GeoPoint", entity.GeoPoint);
		values.put("CreateDate", entity.CreateDate);
		return values;
	}

	@Override
	public Natatoria jsonBuild(JSONObject jsonObject) throws JSONException {
		Natatoria natatoria = new Natatoria();
		natatoria.Id = jsonObject.getInt(root+"Id");
		natatoria.Name = jsonObject.getString(root+"Name");
		natatoria.GeoPoint = jsonObject.getString(root+"GeoPoint");
		natatoria.CreateDate = jsonObject.getString(root+"CreateDate");
		return natatoria;
	}

}
